Data Grid

Change MouseOver Cursor from Arrow to Hand

Description
This customization shows how to change the appearance of cursor when moving over a cell in the DataGrid.
Variables
Table Name
Select a database table to be shown in DataGrid
Applies to
Page class
Code
 
/// 
/// Override the DataBind to populate the DataGrid. Call base.DataBind()
/// and then populate the ASP DataGrid.
///    	
public override void DataBind() 
{
    // Call the base.DataBind()
    base.DataBind();
    if (!this.Page.IsPostBack)
    {
        System.Web.UI.WebControls.DataGrid myDataGrid;
        myDataGrid = ((System.Web.UI.WebControls.DataGrid)(this.FindControlRecursively("myDataGrid")));
        
        // If DataGrid is found then populate it
        if (!(myDataGrid == null))
        {
            string whereStr = null;
            
            // Create orderBy clause
            BaseClasses.Data.OrderBy ob = null;
            
            // Set page index and size
            int pageIndex = 0;
            int pageSize = 1000;
            
            // Set the DataSource of the DataGrid
            myDataGrid.DataSource = ${${Table Name}ClassName}.GetDataTable(whereStr, ob, pageIndex, pageSize);                
            myDataGrid.DataBind();
        }
    }
}
	 
Applies to
Page class
Code
 
/// 
/// This method is called when DataGrid items databind.
/// Set the OnItemDataBound property of the datagrid to have a value of "MyItemDataBound"
/// This function is called everytime an item is bound to the datagrid
/// 
public void MyItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
    if (e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Item || 
        e.Item.ItemType == System.Web.UI.WebControls.ListItemType.AlternatingItem)
    {
        
        // Apply new cursor style for all cells in the DataGrid.
        for(int i = 1; i < (e.Item.Cells.Count); i++)
        {
        
            // Set the new cursor style.
            e.Item.Cells[i].Style["cursor"] = "hand";
        }
    }
}
     

Terms of Service Privacy Statement